package com.example.wendao.view.ui.fragment;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wendao.App;
import com.example.wendao.R;
import com.example.wendao.model.entity.User;
import com.example.wendao.view.viewholder.UserViewHolder;
import com.example.wendao.viewmodel.UserViewModel;

import static android.content.ContentValues.TAG;


/**
 * A simple {@link Fragment} subclass.
 */
public class LookCoinFragment extends Fragment {
    private User user;
    private UserViewModel userViewModel;
    private TextView user_coins_num;
    private ImageView sign_days_imageview;
    private Button button_sign;

    public LookCoinFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_look_user_coin, container, false);
        userViewModel = new ViewModelProvider(App.getInstance()).get(UserViewModel.class);
        user = userViewModel.getCurrentUser();
        String user_cion_num = "3";
        if (user.getCoins() == 0) {

            user_cion_num = String.valueOf(user.getCoins());

        }
        int sign_days = user.getSigndays();

        user_coins_num = view.findViewById(R.id.icon_num_TextView);
        sign_days_imageview = view.findViewById(R.id.sign_imageView);
        button_sign = view.findViewById(R.id.sign_button);
        user_coins_num.setText(user_cion_num);
        switch (sign_days) {
            case 0:
                sign_days_imageview.setImageResource(R.drawable.zero);
            case 1:
                sign_days_imageview.setImageResource(R.drawable.one);
                break;
            case 2:
                sign_days_imageview.setImageResource(R.drawable.two);
                break;
            case 3:
                sign_days_imageview.setImageResource(R.drawable.three);
                break;
            case 4:
                sign_days_imageview.setImageResource(R.drawable.fore);
                break;
            case 5:
                sign_days_imageview.setImageResource(R.drawable.five);
                break;
            default:
                Toast.makeText(view.getContext(), "网络错误，请检查", Toast.LENGTH_LONG).show();
                break;

        }
        button_sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                user.setSigndays(sign_days + 1);
                Toast.makeText(view.getContext(),"签到成功",Toast.LENGTH_SHORT).show();
            }
        });
        return view;

    }

}
